package chapter06

/**
 * 面向对象
 * 类型转换和检测
 * 扩展内容一
 */
object Test17_Extends {

  def main(args: Array[String]): Unit = {
    //1、类型的转换和检测
    val student = new Student17("alice", 18)
    student.study()
    student.sayHi()

    val person: Person17 = new Student17("bob", 20)
    person.sayHi()

    //类型判断
    println("student is Student17: " + student.isInstanceOf[Student17])
    println("student is Person17: " + student.isInstanceOf[Person17])
    println("person is Person17: " + person.isInstanceOf[Person17])
    println("person is Student: " + person.isInstanceOf[Student17])


    val person2: Person17 = new Person17("cary", 35)
    println("person2 is Student17: " + person2.isInstanceOf[Person17])


    //类型转换
    if (person.isInstanceOf[Student17]) {
      //如果包含、直接调用asInstanceOf 方法转换
      val newStudent = person.asInstanceOf[Student17]
      newStudent.study()
    }



  }


}


class Person17(val name: String, val age: Int) {
  def sayHi(): Unit = {
    println("hi form person " + name)
  }
}


class Student17(name: String, age: Int) extends Person17(name, age) {
  override def sayHi(): Unit = {
    println("hi form Student " + name)
  }

  def study(): Unit = {
    println("Student study " + name)
  }
}


//TODO 2、定义枚举类对象

object WorkDay extends Enumeration {
  val MONDAY = Value(1, "MonDay")
  val TuesDay = Value(2, "TuesDay")
}

//应用类
object TestApp extends App {
  println("test app")

  type myString = String
  val a: myString = "张三"
  println(a)
}